package org.example.DesignPatterns.Mediator;

/**
 * @description:
 * @author: farprt
 * @create: 2022-09-24 10:23
 **/
public class PrivateChatRoom extends ChatRoom {
    public PrivateChatRoom(String name) {
        super(name);
    }

    @Override
    protected void register(User user) {
        if(users.size()==2){
            System.out.println("聊天室已满");
            return;
        }
        super.register(user);
        System.out.println("系统消息：欢迎【");
        System.out.println(user.getName());
        System.out.println("】加入2人聊天室【"+name+"】");
    }

    @Override
    protected void deregister(User user) {
        super.deregister(user);
        System.out.println("系统消息："+user.getName()+"离开聊天室");
    }

    @Override
    protected void sendMsg(User from, User to, String msg) {
        users.forEach(user -> user.listen(from,null,msg));
    }

    @Override
    protected String processMsg(User from, User to, String msg) {
        return from.getName()+"说："+msg;
    }
}